/**
 * @文件名称: UserAction.java
 * @类路径:   com.dssrz.weibo4j.action
 * @描述:     TODO
 * @作者:     robin
 * @时间:     2012-3-12 上午11:34:12
 * @版本:     1.0.0
 */
package com.dssrz.weibo4j.action;

import java.util.Calendar;
import java.util.Date;

import org.apache.log4j.Logger;

import com.dssrz.weibo4j.Oauth;
import com.dssrz.weibo4j.Users;
import com.dssrz.weibo4j.http.AccessToken;
import com.dssrz.weibo4j.model.WeiboException;
import com.dssrz.weibo4j.task.TaskCache;

/**
 * @类功能说明:用户登录
 * @类修改者:
 * @修改日期:
 * @修改说明:
 * @作者: robin
 * @创建时间: 2012-3-12 上午11:34:12
 * @版本: 1.0.0
 */

public class UserAction extends BaseAction {

	/**
	 * @Fields serialVersionUID: TODO
	 */
	private static final long serialVersionUID = 4667896284988087720L;

	private static final Logger log = Logger.getLogger(UserAction.class);
	
	public static final String	ACCESS_TOKEN = "2.00VaZmtC09ix3s875d3e272a0CrMOn";

	private String name;
	private String password;

	/**
	 * @return name
	 */
	public String getName() {
		return name;
	}

	/**
	 * @param name
	 *            name
	 */
	public void setName(String name) {
		this.name = name;
	}

	/**
	 * @return password
	 */
	public String getPassword() {
		return password;
	}

	/**
	 * @param password
	 *            password
	 */
	public void setPassword(String password) {
		this.password = password;
	}

	public String localLogin() {
		log.info("本地登录...");
		request.setAttribute("info", "暂不支持");
		request.setAttribute("PageURL", "/login.jsp");
		return "local_fail";
	}

	public String sinaLogin() {
		log.info("新浪微博帐号登录...");
		Oauth oauth = new Oauth();
		// TODO get access_token
		/*
		AccessToken accessToken = null;
		try {
			accessToken = oauth.getAccessTokenByCode("code");
		} catch (WeiboException e) {
			e.printStackTrace();
		}
		String access_token = accessToken.getAccessToken();
		*/
		String access_token = ACCESS_TOKEN;
		Calendar calendar = Calendar.getInstance();
		Date date = new Date();
		calendar.setTime(date);
		request.setAttribute("nowdate", date);
		request.setAttribute("nowhour", calendar.get(Calendar.HOUR_OF_DAY));
		request.setAttribute("nowminute", calendar.get(Calendar.MINUTE));
		request.setAttribute("nextTimer", "10");
		request.getSession().setAttribute("access_token", access_token);
		request.setAttribute("tasks", TaskCache.getTasks(access_token));
		return "sina_success";
	}
}
